<?php
/**
 * @package Curly
 * @version 0.9
 * @link http://curly.codeplex.com/
 * @license http://curly.codeplex.com/license The MIT License
 * @author Dawid Zawada
 */

namespace Curly
{
    /**
     * Class representing a set of HTTP authentication options
     * 
     * @package Curly
     * @license http://curly.codeplex.com/license The MIT License
     */
    class Authentication
    {
        /**
         * Authentiation method
         * 
         * @var Curly\AuthenticationMethod
         */
        protected $method;
        
        /**
         * Authentication login
         * 
         * @var string
         */
        protected $login;
        
        /**
         * Authentication password
         * 
         * @var string
         */
        protected $password;
        
        /**
         * Creates a new Authentication object
         * 
         * @internal
         */
        public function __construct()
        {
            $this->setMethod( AuthenticationMethod::Any() );
            $this->setLoginPassword( "", "" );
        }
        
        /**
         * Returns the authentication method
         *
         * @return Curly\AuthenticationMethod
         */
        public function getMethod()
        {
            return $this->method;
        }
        
        /**
         * Sets the authentication method
         * 
         * @param Curly\AuthenticationMethod $method
         */
        public function setMethod( AuthenticationMethod $method )
        {
            $this->method = $method;
        }
        
        /**
         * Returns the authentication login
         *
         * @return string
         */
        public function getLogin()
        {
            return $this->login;
        }
        
        /**
         * Returns the authentication password
         *
         * @return string
         */
        public function getPassword()
        {
            return $this->password;
        }
        
        /**
         * Returns the authentication login and password with a colon
         * between them
         * 
         * If the login and the password are not set, the method 
         * will return an empty string
         *
         * @return string
         */
        public function getLoginPassword()
        {
            if( $this->getLogin() != "" || $this->getPassword() != "" )
            {
                return $this->getLogin() . ":" . $this->getPassword();
            }
            else
            {
                return "";
            }
        }
        
        /**
         * Sets the authentication login and password
         * 
         * @param string $login
         * @param string $password
         */
        public function setLoginPassword( $login, $password )
        {
            $this->login = (string)$login;
            $this->password = (string)$password;
        }
    }
}